/*
 * File:         ReviewTest.java
 * Author:       Robert Bittle <guywithnose@gmail.com>
 */
package triperest.tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import tests.AppEngineTest;
import triperest.Review;

/**
 * The Class ReviewTest.
 */
public class ReviewTest extends AppEngineTest {

	/** The review. */
	private Review review;
	
	/* (non-Javadoc)
	 * @see tests.AppEngineTest#setUp()
	 */
	@Before
	@Override
	public void setUp()
	{
		super.setUp();
		review = new Review();
		review.userId = "A test User Id";
		review.rank = 3;
		review.comment = "loooooooooooooooooooooooooooooooooooooog winded comment!!!";
	}
	
	/* (non-Javadoc)
	 * @see tests.AppEngineTest#tearDown()
	 */
	@Override
	@After
	public void tearDown()
	{
		if(review.getId() != 0)
			review.delete();
		super.tearDown();
	}
	
	/**
	 * Tests the save method using insert.
	 */
	@Test
	public void testSave_Insert() {
		review.save();
		Review review2 = new Review(review.getId());
		review2.load();
		assertEquals(review.userId, review2.userId);
		assertEquals(review.rank, review2.rank);
		assertEquals(review.comment, review2.comment);
	}
	
	/**
	 * Tests the save method using update.
	 */
	@Test
	public void testSave_Update() {
		review.save();
		review.userId = "Another test User";
		review.rank = 2;
		review.comment = "Another test Comment";
		review.save();
		Review review2 = new Review(review.getId());
		review2.load();
		assertEquals(review.userId, review2.userId);
		assertEquals(review.rank, review2.rank);
		assertEquals(review.comment, review2.comment);
	}
	
	/**
	 * Tests the delete method.
	 */
	@Test
	public void testDelete() {
		review.save();
		assertTrue(review.load());
		review.delete();
		assertFalse(review.load());
	}

}
